package com.ttdevs.tvolley;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;

import com.alibaba.fastjson.JSONObject;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.ttdevs.tvolley.app.VolleyInit;
import com.ttdevs.tvolley.bean.UserInfo;
import com.uns.volley.toolbox.CustomRequest;

public class WebInterfaceActivity extends Activity implements OnClickListener {

	private RequestQueue queue;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_image_loader);

		queue = VolleyInit.getRequestQueue();
	}

	@Override
	public void onClick(View v) {
		UserInfo info = new UserInfo();
		info.setName("Jim");
		info.setNature(true);
		info.setAge(19);
		System.out.println(SystemClock.currentThreadTimeMillis());
		info.setCreate(System.currentTimeMillis());

		CustomRequest req = new CustomRequest(null,1, info, new Response.Listener<JSONObject>() {
			@Override
			public void onResponse(JSONObject response) {
				System.out.println(">>>>>success:" + response.toString());
			}
		}, new Response.ErrorListener() {
			@Override
			public void onErrorResponse(VolleyError error) {
				System.out.println(">>>>>error:" + error.getMessage());
			}
		});
		req.setTag("userinfo");
		
		queue.add(req);
		queue.add(req);
	}
	
	@Override
	protected void onDestroy() {
		queue.cancelAll("userinfo");
		super.onDestroy();
	}

	// private Response.Listener<JSONObject> createMyReqSuccessListener() {
	// return new Response.Listener<JSONObject>() {
	// @Override
	// public void onResponse(JSONObject response) {
	// // setTvResultText(response.toString());
	// }
	// };
	// }
	//
	// private Response.ErrorListener createMyReqErrorListener() {
	// return new Response.ErrorListener() {
	// @Override
	// public void onErrorResponse(VolleyError error) {
	// // tvResult.setText(error.getMessage());
	// }
	// };
	// }
}
